package com.ssm.controller;

import com.ssm.entity.Student;
import com.ssm.service.StudentService;
import com.ssm.utils.PageResult;

import com.ssm.utils.R;
import com.ssm.vo.StudentVo;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")

public class StudentController {
    private final StudentService studentService;

    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }
    @RequestMapping("/findAll")
    public List<Student> findAll(){
        return studentService.findAll();
    }
    @RequestMapping("/findByPage")
    public PageResult<Student> findByPage(Integer page, Integer pageSize){
        return studentService.findByPage(page,pageSize);
    }
    @PostMapping("/conditionFindByPage")
    public PageResult<Student> conditionFindByPage(Integer page, Integer pageSize, @RequestBody StudentVo studentVo){
        return studentService.conditionFindByPage(page,pageSize,studentVo);
    }
    @PostMapping("/addStudent")
    public R addStudent(@RequestBody Student student){
        if (studentService.addStudent(student)){
            return R.ok().message("插入成功!");
        }
        return R.error();
    }
}
